//
//  HomeGridButton.swift
//  SitPosition
//
//  Created by apple on 2019/1/1.
//  Copyright © 2019 apple. All rights reserved.
//

import Foundation
import UIKit
import Cartography


/**
 * 主页网格大按钮封装类
 */
class HomeGridButton : UIControl {
    
    lazy var titleLabel: UILabel = {
        let label = UILabel()
        label.textColor = Theme.Color.primaryLightTextColor
        label.font = Theme.Font.regularFont(ofSize: 14)
        label.lineBreakMode = .byTruncatingTail
        label.numberOfLines = 1
        return label
    }()
    
    lazy var backgroundIV: UIImageView = {
        let iv = UIImageView()
        iv.contentMode = UIView.ContentMode.scaleAspectFill
        iv.clipsToBounds = true
        return iv
    }()
    
    init(title: String, backgroundImage: UIImage?) {
        super.init(frame: CGRect.zero)
        titleLabel.text = title
        backgroundIV.image = backgroundImage
        _commonInit()
    }
    
    override init(frame: CGRect) {
        fatalError()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError()
    }
    
    func _commonInit() {
        addSubviews([
            titleLabel,
            backgroundIV
        ])
        
        constrain(titleLabel, self) { v, parent in
            v.left == parent.left + 10
            v.top == parent.top + 15
            v.right == parent.right - 10
            v.height == 14
        }
        
        constrain(backgroundIV, self) { v, parent in
            v.edges == parent.edges
        }
        bringSubviewToFront(titleLabel)
    }
}
